<?php
include_once "DBCORE.cls.php";
	/**
	*  
	*/
	class db_Menu
	{
		private $tablename="tblmenu";
		private $db;
		function __construct()
		{
			$this->db=new DBCORE();
			$this->db->db_connect("localhost", "root", "", "restaurant");
			$this->db->db_query("SET NAMES 'UTF8'");
		}
		
		public function select($id)
		{
			if(empty($id))
				return false;
			$id = ("WHERE MenuID = '{$this->db->db_real_escape_string($id)}'");
			$myStrSQL = "SELECT * FROM {$this->tablename} {$id}";
			$data = $this->db->db_fetch_assoc($this->db->db_query($myStrSQL));
			return $data;
		}
		//
		
		public function selectAllMenu($ResID = '')
		{
			if(empty($ResID))
				return false;
			$condition = "WHERE RestaurantID = '{$this->db->db_real_escape_string($ResID)}'";
			$myStrSQL = "SELECT MenuID,NameMenu FROM {$this->tablename} {$condition}";
			$result = $this->db->db_query($myStrSQL);
			$resArray = array();
			while($row = $this->db->db_fetch_assoc($result))
			{
				$resArray[] = $row;
			}
			return $resArray;
		}
		//
		
		public function insert($data = array())
		{
			if(empty($data))
				return false;
			$id = $data['ID'];
			$resId = $data['ResID'];
			$name = $data['Name'];
			$myStrSQL = "INSERT INTO {$this->tablename} VALUES('$id', '$resId', '$name')";
			return $this->db->db_query($myStrSQL);
		}
		//
		
		public function update($data)
		{
			if(empty($data))
				return false;
			$myStrSQL = "UPDATE {$this->tablename} SET NameMenu='{$data['Name']}' WHERE MenuID ='{$data['ID']}'";
			echo $myStrSQL;
		}
		//
		
		public function delete($id)
		{
			if(empty($data))
				return false;
			$id = ("WHERE MenuID = '{$this->db->db_real_escape_string($id)}'");
			$myStrSQL = "DELETE * FROM {$this->tablename} {$id}";
			$this->db->db_query($myStrSQL);
			return $this->db->db_affected_rows();
		}
		public function deleteAll($ResID)
		{
			if(empty($ResID))
				return false;
			$id = ("WHERE RestaurantID = '{$this->db->db_real_escape_string($ResID)}'");
			$myStrSQL = "DELETE * FROM {$this->tablename} {$id}";
			$this->db->db_query($myStrSQL);
			return $this->db->db_affected_rows();
		}
}
?>